package net.garbage;

import java.io.IOException;
import java.io.OutputStream;
import java.net.Socket;
import java.util.ArrayList;

/**
 * @author Jose Martin Rozanec;
 */
public class RemoteFileInputServer extends NetServer {
    private String serverName;

    public RemoteFileInputServer(int portnum) {
        super(portnum);
    }

    public RemoteFileInputServer(int portnum, String serverName) {
        super(portnum);
        this.serverName = serverName;
    }

    protected void createClientPort(Socket socket) {
        try {
            new ClientPort(this, socket);
        }
        catch (IOException ioe) {
        }
    }

    public static void main(String argv[]) {
        RemoteFileInputServer remoteFileInputServer = new RemoteFileInputServer(9005);
        remoteFileInputServer.setServerName("PepitoGonzalez - Server");
        Socket socket;
        java.util.List<Socket> socketList = new ArrayList<Socket>();
        for (int j = 0; j < 3; j++) {
            try {
                socket = new Socket("127.0.0.1", 9005);
                socketList.add(socket);
                remoteFileInputServer.createClientPort(socket);
                System.out.println("Succesful operation!");
            } catch (IOException e) {
                System.out.println("Could not connect:(");
            }
        }
        try {
            OutputStream stream = socketList.get(0).getOutputStream();
            for (int j = 0; j < 3; j++) {
                stream.write(0);
            }
        } catch (IOException e) {
            System.out.println("Couldnt get input stream...");
        }
    }
}